﻿/** \file
* \$Rev: 5 $
* 
* \$Date: 2010-06-23 12:53:30 +0000 (Wed, 23 Jun 2010) $
*
* \$URL: http://fofbrainz.googlecode.com/svn/trunk/MainForm.cs $
*/

using System;
using System.IO;
using System.Windows.Forms;

namespace FofBrainz
{
	/// <summary>The main application form.</summary>
	partial class MainForm : Form
	{
		public MainForm()
		{
			InitializeComponent();

			textSongDir.DataBindings.Add(new Binding("Text", Program.settings, "songdir"));
			numMaxTries.DataBindings.Add(new Binding("Value", Program.settings, "maxtries"));
			checkExact.DataBindings.Add(new Binding("Checked", Program.settings, "exactmatch"));
		}

		/// <summary>Set the progress maximum (thread-safe).</summary>
		/// <param name="max">The maximum progress value.</param>
		public void SetProgressMax(int max)
		{
			progressWork.Invoke((MethodInvoker)delegate { progressWork.Maximum = max; });
		}

		/// <summary>Show a single progress tick.</summary>
		public void Tick()
		{
			progressWork.Invoke((MethodInvoker)delegate { progressWork.Value++; });
		}

		private void buttonStart_Click(object sender, EventArgs e)
		{
			groupSettings.Enabled = false;
			Program.StartWorker();
		}

		/// <summary>Write out a log line and a newline.</summary>
		/// <param name="str">The log line to write.</param>
		public void Log(string str)
		{
			textLog.Invoke((MethodInvoker)delegate
			{
				textLog.Text += str + Environment.NewLine;
				textLog.SelectionLength = 0;
				textLog.SelectionStart = textLog.Text.Length;
				textLog.ScrollToCaret();
			});
		}

		private void textSongDir_TextChanged(object sender, EventArgs e)
		{
			buttonStart.Enabled = Directory.Exists(textSongDir.Text);
		}
	}
}
